#include "functions.h"
	
Function::Function()
{
}
Function:: ~Function()
{
}

BinaryOperator::BinaryOperator(Function * a, Function * b)
	:left(a),
	 right(b)
{
}
BinaryOperator::~BinaryOperator()
{
}

Plus::Plus(Function * a, Function * b)
	:BinaryOperator(a,b)
{ 
}
Plus::~Plus()
{
}
double Plus::F(double x)
{
	return left->F(x) + right->F(x);
}

Minus::Minus(Function * a, Function * b)
	:BinaryOperator(a,b)
{ 
}
Minus::~Minus()
{
}
double Minus::F(double x)
{
	return left->F(x) - right->F(x);
}

Mull::Mull(Function * a, Function * b)
	:BinaryOperator(a,b)
{ 
}
Mull::~Mull()
{
}
double Mull::F(double x)
{
	return left->F(x) * right->F(x);
}

Div::Div(Function * a, Function * b)
	:BinaryOperator(a,b)
{
}
Div::~Div()
{
}
double Div::F(double x)
{
	return left->F(x) / right->F(x);
}

Const::Const(double x)
	:value(x)
{
}
Const::~Const()
{
}
double Const::F(double x)
{
	return value;
}

Var::Var()
{
}
Var::~Var()
{
}
double Var::F(double x)
{
	return x;
}

Function * Typer::newFunction(Function * a, Function * b, std::string type)
{
	if(type == "*")
	{
		return new Mull(a,b);
	}
	if(type == "/")
	{
		return new Div(a,b);
	}
	if(type == "-")
	{
		return new Minus(a,b);
	}
	if(type == "+")
	{
		return new Plus(a,b);
	}
	return new Plus(a,b);
}
Function * Typer::newFunction(double x)
{
	return new Const(x);
}
Function * Typer::newFunction()
{
	return new Var();
}